/*
 * LineVector.java
 *
 * Created on 6. Oktober 2002, 09:46
 */

package com.math3d;

import javax.media.j3d.Appearance;
import javax.media.j3d.GraphicsContext3D;
import javax.media.j3d.LineArray;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;

import com.game.obj.GameObject;
import com.render3d.ms3d.Model3D;


/**
 * Class provides drawing a simple line.
 *
 * @author  Norbert Nopper
 */
public class LineVector extends Model3D {
    
    /**
     * Class variable for the red color.
     */
    final public static Color3f RED = new Color3f(1.0f, 0.0f, 0.0f);
    
    /**
     * Class variable for the green color.
     */
    final public static Color3f GREEN = new Color3f(0.0f, 1.0f, 0.0f);

    /**
     * Class variable for the blue color.
     */
    final public static Color3f BLUE = new Color3f(0.0f, 0.0f, 1.0f);
    
    /**
     * The line itself.
     */
    private LineArray   line;
    
    /**
     * Default appearance.
     */
    private Appearance  appearance;
    
    /**
     * Creates a vector starting from (0,0,0) to the given point. 
     *
     * @param direction the vector where the line is pointing
     * @param color     the color of the line
     */
    public LineVector(Point3d direction, Color3f color) {
        // create the line array ...
        line = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3 );
        // ... set the coordinates ...
        line.setCoordinate(0, new Point3d(0.0, 0.0, 0.0));
        line.setCoordinate(1, direction);
        // ... and the color
        line.setColor(0, color);
        line.setColor(1, color);

        // create the default appearance
        appearance = new Appearance();
    }

    /**
     * Nothing needs to be updated.
     *
     * @param time the passed time in milliseconds
     */
    protected void updateModel(Transform3d camera, GameObject player, long exTime) {
        // do nothing
    }
    
    /**
     * Render the line.
     *
     * @param gc3D the graphics contect 3D to render on
     */    
    protected void drawModel(GraphicsContext3D gc3D) {        
        gc3D.setAppearance(appearance);
        
        gc3D.draw(line);        
    }
    
}
